<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>定时任务</title>
    <link rel="stylesheet" href="/layui/v10/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
    <style>
        #demoTabsHeader .layui-btn.layui-this {
            border-color: #eee;
            color: unset;
            background: none;
        }

        #demoTabsBody .test-item {
            display: none;
        }

        .layui-table th,
        .layui-table td {
            text-align: center !important;
        }

        .layui-container {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div id="dsrwTabs" class="layui-card-body">
                    <div class="layui-btn-container" id="demoTabsHeader">
                        <button class="layui-btn layui-this">系统定时任务</button>
                        <button class="layui-btn">定时任务日志</button>
                    </div>
                    <div id="demoTabsBody">
                        <div class="test-item layui-show">
                            <div class="layui-container">
                                <div class="layui-form">
                                    <div class="layui-form-item">
                                        <div class="layui-input-inline">
                                            <label for="id"></label>
                                            <input type="text" id="id" class="layui-input" autocomplete="off"
                                                   placeholder="请输入定时任务ID">
                                        </div>
                                        <div class="layui-input-inline">
                                            <label for="beanName"></label>
                                            <input type="text" id="beanName" class="layui-input" autocomplete="off"
                                                   placeholder="请输入定时任务名称">
                                        </div>
                                        <div class="layui-input-inline ">
                                            <button class="layui-btn" onclick="searchDsrw()" id="searchDsrw">查询
                                            </button>
                                            <button class="layui-btn" id="exportDsrw">导出全部</button>
                                        </div>
                                    </div>

                                </div>
                                <table class="layui-table" id="dsrwTable" lay-filter="dsrwTable"></table>
                            </div>
                        </div>
                        <div class="test-item">
                            <div class="layui-form">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        <label for="dsrwid"></label>
                                        <input type="text" id="dsrwid" class="layui-input" autocomplete="off"
                                               placeholder="请输入定时任务ID">
                                    </div>
                                    <div class="layui-input-inline">
                                        <label for="dsrwmc"></label>
                                        <input type="text" id="dsrwmc" class="layui-input" autocomplete="off"
                                               placeholder="请输入定时任务名称">
                                    </div>
                                    <div class="layui-input-inline ">
                                        <button class="layui-btn" onclick="search()" id="search">查询</button>
                                        <button class="layui-btn" id="export">导出全部</button>
                                    </div>
                                </div>
                            </div>
                            <table class="layui-table" id="dsrwlogTable" lay-filter="dsrwlogTable"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layui/v10/layui.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    //获取token
    let token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    let tokenQuery = token.replace("#", "%23");
    let tableIns1;
    let tableIns2;
    let table = layui.table;
    let form = layui.form;
    let layer = layui.layer;
    let $ = jQuery = layui.jquery;
    let laydate = layui.laydate;
    let tabs = layui.tabs;
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        // 给任意元素绑定 Tab 功能
        tabs.render({
            elem: '#dsrwTabs',
            header: ['#demoTabsHeader', '>button'],
            body: ['#demoTabsBody', '>.test-item']
        });

        //定时任务日志表
        tableIns1 = table.render({
            elem: '#dsrwlogTable'
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , url: '/sysJob/queryXtrw' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    // {type: 'checkbox', fixed: 'left'},
                    {field: 'dsrwid', title: '任务id', width: 100, align: "center", sort: true},
                    {field: 'dsrwmc', title: '定时任务名称', width: 280, align: "center", sort: true},
                    {field: 'bmc', title: '表名称', width: 160, align: "center", sort: true},
                    {field: 'zxqk', title: '执行情况', width: 160, align: "center", sort: true},
                    {field: 'zxsj', title: '执行时间', width: 160, align: "center", sort: true},
                    {field: 'zxqksm', title: '执行情况说明', width: 800, align: "center", sort: true},
                ]
            ]
            , toolbar: '#toolbar'
        });
        tableIns2 = table.render({
            elem: '#dsrwTable'
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , url: '/sysJob/queryDsrw' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    // {type: 'checkbox', fixed: 'left'},
                    {field: 'id', title: '任务id', width: 100, align: "center", sort: true},
                    {field: 'jobName', title: '定时任务名称', width: 300, align: "center", sort: true},
                    {field: 'systemName', title: '关联功能', width: 300, align: "center", sort: true},
                    {field: 'bmc', title: '关联表名', width: 500, align: "center", sort: true},
                    {field: 'remark', title: '执行时间', width: 200, align: "center", sort: true},
                    {
                        field: 'createTime',
                        title: '创建时间',
                        width: 200,
                        align: "center",
                        sort: true,
                        templet: function (d) {
                            if (!d.createTime) {
                                return '';
                            }
                            return layui.util.toDateString(d.createTime, 'yyyy-MM-dd');
                        }
                    },
                ]
            ]
            , toolbar: '#toolbar'
        });

    });

    //执行查询
    function search() {
        //这里以搜索为例
        tableIns1.reload({
            where: { //设定异步数据接口的额外参数，任意设
                dsrwid: $("#dsrwid").val(),
                dsrwmc: $("#dsrwmc").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

    //执行查询
    function searchDsrw() {
        //这里以搜索为例
        tableIns2.reload({
            where: { //设定异步数据接口的额外参数，任意设
                id: $("#id").val(),
                beanName: $("#beanName").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }


</script>
</body>
</html>